{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2022, 11, 28, 15, 0)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "datetime.fromtimestamp(1669618800)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ag'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"agL9\"[:-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2022, 11, 29, 15, 0)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "datetime.fromtimestamp(1669705200)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2022, 11, 30, 15, 0)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.fromtimestamp(1669791600)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2023-03-08 15:00:00\n",
      "2023-03-07 15:00:00\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "print(datetime.fromtimestamp(1678258800))\n",
    "print(datetime.fromtimestamp(1678172400))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2023, 3, 6, 15, 0)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.fromtimestamp(1678086000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "L6\n",
      "ag\n"
     ]
    }
   ],
   "source": [
    "print(\"agL6\"[-2:])\n",
    "print(\"agL6\"[:-2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n",
      "[]\n"
     ]
    }
   ],
   "source": [
    "a = []\n",
    "b = list(reversed(a))\n",
    "print(a)\n",
    "print(b)\n",
    "for i in range(len(b)):\n",
    "    print(b[i])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3]\n"
     ]
    }
   ],
   "source": [
    "a = [0, 1, 2, 3, 4, 5, 6, 7, 8]\n",
    "print(a[3+1-3:3+1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sys.path[0]:  e:\\work\\py\\ConditionStrategy\\ipynb\n",
      "getcwd:  e:\\work\\py\\ConditionStrategy\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import sys\n",
    "os.chdir(os.path.dirname(sys.path[0]))\n",
    "from base.BaseCD import CCL\n",
    "print(\"sys.path[0]: \", sys.path[0])\n",
    "print(\"getcwd: \", os.getcwd()) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ag'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import string\n",
    "\"ag2305\".rstrip(string.digits)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ag'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"agL9\"[:-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 4, 5, 6, 7]\n"
     ]
    }
   ],
   "source": [
    "a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
    "print(a[7+1-5:7+1])\n",
    "for item in "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'15:10:11'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\"2022-05-06 15:10:11\"[-8:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-4.019615127424029"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(26918-28000)/26918 * 100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2023, 5, 19, 11, 30)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from datetime import datetime \n",
    "datetime.fromtimestamp(1684467000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2023, 5, 22, 9, 30)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "datetime.fromtimestamp(1684719000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2022-12-06 15:00:00\n",
      "2022-12-07 15:00:00\n",
      "2022-12-08 15:00:00\n",
      "2023-05-15 15:00:00\n",
      "2023-05-16 15:00:00\n",
      "2023-05-17 15:00:00\n",
      "2023-05-18 15:00:00\n",
      "2023-04-27 15:00:00\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "print(datetime.fromtimestamp(1670310000))\n",
    "print(datetime.fromtimestamp(1670396400))\n",
    "print(datetime.fromtimestamp(1670482800\n",
    "))\n",
    "print(datetime.fromtimestamp(1684134000\n",
    "\n",
    "))\n",
    "print(datetime.fromtimestamp(1684220400\n",
    "\n",
    "))\n",
    "print(datetime.fromtimestamp(1684306800\n",
    "\n",
    "))\n",
    "print(datetime.fromtimestamp(1684393200\n",
    "\n",
    "))\n",
    "print(datetime.fromtimestamp(1682578800\n",
    "\n",
    "))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n"
     ]
    }
   ],
   "source": [
    "a = []\n",
    "a = a[1:]\n",
    "print(a)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1684719960"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "t = datetime.strptime(\"2023-05-22 09:46:00\", \"%Y-%m-%d %H:%M:%S\")\n",
    "int(t.timestamp())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2023-05-22 20:01:07.078083 2023-05-22 20:01:00\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime, timedelta\n",
    "t = datetime.now()\n",
    "t2 = t.replace(second=0, microsecond=0)\n",
    "print(t, t2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(1, 5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "14：30 2023-05-25 15:00:00\n",
      "14：45 2023-05-26 11:15:00\n",
      "14：45 2023-05-26 14:15:00\n",
      "2023-05-26 14:30:00\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "print(\"14：30\", datetime.fromtimestamp(1684998000))\n",
    "print(\"14：45\", datetime.fromtimestamp(1685070900))\n",
    "print(\"14：45\", datetime.fromtimestamp(1685081700))\n",
    "print(datetime.fromtimestamp(1685082600))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'a'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import string\n",
    "codeL = \"a2009\"\n",
    "codeL.rstrip(string.digits)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2023-04-30 11:45:00\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime, timedelta\n",
    "t = datetime.strptime(\"2022-12-01 11:45:00\", \"%Y-%m-%d %H:%M:%S\")\n",
    "t2 = t + timedelta(days=150)\n",
    "print(t2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             open   high    low  close        amount      volume\n",
      "date                                                            \n",
      "2002-04-09  10.51  10.88  10.51  10.66  4.418822e+09  4141088.00\n",
      "2002-04-10  10.66  10.70  10.39  10.60  7.166843e+08   679454.00\n",
      "2002-04-11  10.60  10.68  10.49  10.52  2.409635e+08   227882.00\n",
      "2002-04-12  10.50  10.64  10.48  10.57  2.240599e+08   212564.00\n",
      "2002-04-15  10.57  10.60  10.35  10.39  1.933069e+08   185311.00\n",
      "...           ...    ...    ...    ...           ...         ...\n",
      "2023-05-19  34.35  34.45  33.94  33.95  1.339332e+09   392989.80\n",
      "2023-05-22  33.98  34.34  33.98  34.20  1.014463e+09   296934.41\n",
      "2023-05-23  34.21  34.38  33.60  33.60  1.177389e+09   346921.26\n",
      "2023-05-24  33.59  33.59  32.93  32.93  1.541649e+09   463998.73\n",
      "2023-05-25  32.76  32.76  32.16  32.42  2.286618e+09   706051.03\n",
      "\n",
      "[5058 rows x 6 columns]\n"
     ]
    }
   ],
   "source": [
    "from pytdx.reader import TdxDailyBarReader, TdxFileNotFoundException\n",
    "reader = TdxDailyBarReader()\n",
    "df = reader.get_df(\"C:/Users/admin/Downloads/shlday_4/sh600036.day\")\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = set()\n",
    "a = {15, 30, 60, 120, 1440}\n",
    "16 in a\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "string indices must be integers",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[3], line 8\u001b[0m\n\u001b[0;32m      6\u001b[0m start\u001b[39m=\u001b[39mdatetime\u001b[39m.\u001b[39mdatetime(\u001b[39m2006\u001b[39m,\u001b[39m1\u001b[39m,\u001b[39m1\u001b[39m) \n\u001b[0;32m      7\u001b[0m end\u001b[39m=\u001b[39mdatetime\u001b[39m.\u001b[39mdatetime(\u001b[39m2016\u001b[39m,\u001b[39m1\u001b[39m,\u001b[39m1\u001b[39m)\n\u001b[1;32m----> 8\u001b[0m BAC\u001b[39m=\u001b[39mdata\u001b[39m.\u001b[39;49mDataReader(\u001b[39m'\u001b[39;49m\u001b[39m000001.sz\u001b[39;49m\u001b[39m'\u001b[39;49m,\u001b[39m'\u001b[39;49m\u001b[39myahoo\u001b[39;49m\u001b[39m'\u001b[39;49m,start,end) \n\u001b[0;32m      9\u001b[0m \u001b[39mprint\u001b[39m(BAC)\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\envs\\pydev3.11\\lib\\site-packages\\pandas\\util\\_decorators.py:211\u001b[0m, in \u001b[0;36mdeprecate_kwarg.<locals>._deprecate_kwarg.<locals>.wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    209\u001b[0m     \u001b[39melse\u001b[39;00m:\n\u001b[0;32m    210\u001b[0m         kwargs[new_arg_name] \u001b[39m=\u001b[39m new_arg_value\n\u001b[1;32m--> 211\u001b[0m \u001b[39mreturn\u001b[39;00m func(\u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\envs\\pydev3.11\\lib\\site-packages\\pandas_datareader\\data.py:370\u001b[0m, in \u001b[0;36mDataReader\u001b[1;34m(name, data_source, start, end, retry_count, pause, session, api_key)\u001b[0m\n\u001b[0;32m    367\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mNotImplementedError\u001b[39;00m(msg)\n\u001b[0;32m    369\u001b[0m \u001b[39mif\u001b[39;00m data_source \u001b[39m==\u001b[39m \u001b[39m\"\u001b[39m\u001b[39myahoo\u001b[39m\u001b[39m\"\u001b[39m:\n\u001b[1;32m--> 370\u001b[0m     \u001b[39mreturn\u001b[39;00m YahooDailyReader(\n\u001b[0;32m    371\u001b[0m         symbols\u001b[39m=\u001b[39;49mname,\n\u001b[0;32m    372\u001b[0m         start\u001b[39m=\u001b[39;49mstart,\n\u001b[0;32m    373\u001b[0m         end\u001b[39m=\u001b[39;49mend,\n\u001b[0;32m    374\u001b[0m         adjust_price\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m    375\u001b[0m         chunksize\u001b[39m=\u001b[39;49m\u001b[39m25\u001b[39;49m,\n\u001b[0;32m    376\u001b[0m         retry_count\u001b[39m=\u001b[39;49mretry_count,\n\u001b[0;32m    377\u001b[0m         pause\u001b[39m=\u001b[39;49mpause,\n\u001b[0;32m    378\u001b[0m         session\u001b[39m=\u001b[39;49msession,\n\u001b[0;32m    379\u001b[0m     )\u001b[39m.\u001b[39;49mread()\n\u001b[0;32m    381\u001b[0m \u001b[39melif\u001b[39;00m data_source \u001b[39m==\u001b[39m \u001b[39m\"\u001b[39m\u001b[39miex\u001b[39m\u001b[39m\"\u001b[39m:\n\u001b[0;32m    382\u001b[0m     \u001b[39mreturn\u001b[39;00m IEXDailyReader(\n\u001b[0;32m    383\u001b[0m         symbols\u001b[39m=\u001b[39mname,\n\u001b[0;32m    384\u001b[0m         start\u001b[39m=\u001b[39mstart,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    390\u001b[0m         session\u001b[39m=\u001b[39msession,\n\u001b[0;32m    391\u001b[0m     )\u001b[39m.\u001b[39mread()\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\envs\\pydev3.11\\lib\\site-packages\\pandas_datareader\\base.py:253\u001b[0m, in \u001b[0;36m_DailyBaseReader.read\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    251\u001b[0m \u001b[39m# If a single symbol, (e.g., 'GOOG')\u001b[39;00m\n\u001b[0;32m    252\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39msymbols, (string_types, \u001b[39mint\u001b[39m)):\n\u001b[1;32m--> 253\u001b[0m     df \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_read_one_data(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49murl, params\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_get_params(\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msymbols))\n\u001b[0;32m    254\u001b[0m \u001b[39m# Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT'])\u001b[39;00m\n\u001b[0;32m    255\u001b[0m \u001b[39melif\u001b[39;00m \u001b[39misinstance\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39msymbols, DataFrame):\n",
      "File \u001b[1;32md:\\ProgramData\\Anaconda3\\envs\\pydev3.11\\lib\\site-packages\\pandas_datareader\\yahoo\\daily.py:153\u001b[0m, in \u001b[0;36mYahooDailyReader._read_one_data\u001b[1;34m(self, url, params)\u001b[0m\n\u001b[0;32m    151\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m    152\u001b[0m     j \u001b[39m=\u001b[39m json\u001b[39m.\u001b[39mloads(re\u001b[39m.\u001b[39msearch(ptrn, resp\u001b[39m.\u001b[39mtext, re\u001b[39m.\u001b[39mDOTALL)\u001b[39m.\u001b[39mgroup(\u001b[39m1\u001b[39m))\n\u001b[1;32m--> 153\u001b[0m     data \u001b[39m=\u001b[39m j[\u001b[39m\"\u001b[39;49m\u001b[39mcontext\u001b[39;49m\u001b[39m\"\u001b[39;49m][\u001b[39m\"\u001b[39;49m\u001b[39mdispatcher\u001b[39;49m\u001b[39m\"\u001b[39;49m][\u001b[39m\"\u001b[39;49m\u001b[39mstores\u001b[39;49m\u001b[39m\"\u001b[39;49m][\u001b[39m\"\u001b[39;49m\u001b[39mHistoricalPriceStore\u001b[39;49m\u001b[39m\"\u001b[39;49m]\n\u001b[0;32m    154\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyError\u001b[39;00m:\n\u001b[0;32m    155\u001b[0m     msg \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mNo data fetched for symbol \u001b[39m\u001b[39m{}\u001b[39;00m\u001b[39m using \u001b[39m\u001b[39m{}\u001b[39;00m\u001b[39m\"\u001b[39m\n",
      "\u001b[1;31mTypeError\u001b[0m: string indices must be integers"
     ]
    }
   ],
   "source": [
    "from pandas_datareader import data, wb\n",
    "from pandas_datareader import data, wb\n",
    "import pandas as pd\n",
    "import numpy as np \n",
    "import datetime \n",
    "start=datetime.datetime(2006,1,1) \n",
    "end=datetime.datetime(2016,1,1)\n",
    "BAC=wb.DataReader('000001.sz','yahoo',start,end) \n",
    "print(BAC)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
